Demonstrations of the Gradient, Divergence, and Curl

Gradients

2-D

Manipulate[

Module[{zoomScale,viewDomain,howBig, plotOpts,plotOptsType, paramSubst},

(* ImageSize of graph in pixels *)
howBig=150; 

(* Compute domain/range based on location of center and zoom settings *)
zoomScale[factor_]=(factor^3);
viewDomain[centerpt_,var_:0,radius_:zoomScale[zoomFactor]]:=If[NumberQ[var],{-Abs[radius]+centerpt,Abs[radius]+centerpt},
{var,
-Abs[radius]+centerpt,Abs[radius]+centerpt}];

(* Substitution rules for parameters used in user-entered equations *)
paramSubst={A->paramA,B->paramB,C->paramC};

(* Plot options common to all plots *)
plotOpts ={ImageSize->howBig};
plotOptsType=Options[ContourPlot];

Column[{Plot3D[Tooltip[xyFunction/.paramSubst],Evaluate[viewDomain[viewPt[[1]],x]],
Evaluate[viewDomain[viewPt[[2]],y]],
Evaluate[FilterRules[plotOpts,plotOptsType]],ViewPoint->{0,-1,1},ClippingStyle->None],Show[ContourPlot[Tooltip[xyFunction/.paramSubst],Evaluate[viewDomain[viewPt[[1]],x]],
Evaluate[viewDomain[viewPt[[2]],y]],
ClippingStyle->Automatic],GradientFieldPlot[xyFunction/.paramSubst,Evaluate[viewDomain[viewPt[[1]],x]],
Evaluate[viewDomain[viewPt[[2]],y]],VectorHeads->True],Evaluate[FilterRules[plotOpts,plotOptsType]]]}]],
Style["Graph of f[x,y], its level curves, and its gradient field."],
{{xyFunction,(x^2)-(y^2),"f[x,y] = "}},
Style["Zoom"],
{{zoomFactor,1.2,""},6,0.1,ControlType->VerticalSlider,ControlPlacement->Left},
{{viewPt,{0,0},""},{-20,-20},{20,20},ControlPlacement->Right},
Delimiter,
{{paramA,1,"(+ integers) A"},0,50,1,Appearance->"Labeled",ControlPlacement->Bottom},
{{paramB,1,"(+/- integers) B"},-10,10,1,Appearance->"Labeled",ControlPlacement->Bottom},
{{paramC,0,"(+/- reals) C"},-1,1,Appearance->"Labeled",ControlPlacement->Bottom},Initialization:>(Needs["VectorFieldPlots`"])
]

3-D

Manipulate[

Module[{zoomScale,viewDomain,howBig, plotOpts,plotOptsType, paramSubst},

(* ImageSize of graph in pixels *)
howBig=220; 

(* Compute domain/range based on location of center and zoom settings *)
zoomScale[factor_]=(factor^3);
viewDomain[centerpt_,var_:0,radius_:zoomScale[zoomFactor]]:=If[NumberQ[var],{-Abs[radius]+centerpt,Abs[radius]+centerpt},
{var,
-Abs[radius]+centerpt,Abs[radius]+centerpt}];

(* Substitution rules for parameters used in user-entered equations *)
paramSubst={A->paramA,B->paramB,C->paramC};

(* Plot options common to all plots *)
plotOpts ={ImageSize->howBig};
plotOptsType=Options[ContourPlot3D];

Show[GradientFieldPlot3D[Evaluate[xyzFunction/.paramSubst],Evaluate[viewDomain[0,x]],
Evaluate[viewDomain[0,y]],Evaluate[viewDomain[0,z]],VectorHeads->True],ContourPlot3D[Tooltip[xyzFunction/.paramSubst],Evaluate[viewDomain[0,x]],
Evaluate[viewDomain[0,y]],Evaluate[viewDomain[0,z]],Contours->contoursToDraw,ContourStyle->Opacity[0.9]],Evaluate[FilterRules[plotOpts,plotOptsType]]]],
Style["Graph of level surfaces and gradient field of f[x,y,z]."],
{{xyzFunction,(x^2)+(y^2)-(z^2),"f[x,y,z] = "}},
{{contoursToDraw,5,"Level surfaces:"},1,20,1,Appearance->"Labeled"},
Style["Zoom"],
{{zoomFactor,1.2,""},6,0.1,ControlType->VerticalSlider,ControlPlacement->Left},
Delimiter,
{{paramA,1,"(+ integers) A"},0,50,1,Appearance->"Labeled",ControlPlacement->Bottom},
{{paramB,1,"(+/- integers) B"},-10,10,1,Appearance->"Labeled",ControlPlacement->Bottom},
{{paramC,0,"(+/- reals) C"},-1,1,Appearance->"Labeled",ControlPlacement->Bottom}
]

Divergence

Manipulate[

Module[{zoomScale,viewDomain,howBig, plotOpts,plotOptsType, paramSubst,div2,field2},

(* ImageSize of graph in pixels *)
howBig=190; 

(* Compute domain/range based on location of center and zoom settings *)
zoomScale[factor_]=(factor^3);
viewDomain[centerpt_,var_:0,radius_:zoomScale[zoomFactor]]:=If[NumberQ[var],{-Abs[radius]+centerpt,Abs[radius]+centerpt},
{var,
-Abs[radius]+centerpt,Abs[radius]+centerpt}];

(* Substitution rules for parameters used in user-entered equations *)
paramSubst={A->paramA,B->paramB,C->paramC};

(* Plot options common to all plots *)
plotOpts ={ImageSize->howBig};
plotOptsType=Options[ContourPlot];

div2[field_]:=(∂_x) field[[1]]+(∂_y) field[[2]];
field2[x_,y_]:={vFunction1,vFunction2}/.paramSubst;

Show[ContourPlot[Evaluate[div2[field2[x,y]]],Evaluate[viewDomain[viewPt[[1]],x]],
Evaluate[viewDomain[viewPt[[2]],y]],RegionFunction->(#3>0&),ColorFunction->(RGBColor[#1/2+0.5,#1/2+0.5,0]&),ClippingStyle->Automatic],ContourPlot[Evaluate[div2[field2[x,y]]],Evaluate[viewDomain[viewPt[[1]],x]],
Evaluate[viewDomain[viewPt[[2]],y]],RegionFunction->(#3<0&),ColorFunction->(RGBColor[0,0,0.8#1]&),ClippingStyle->Automatic],ContourPlot[Evaluate[div2[field2[x,y]]],Evaluate[viewDomain[viewPt[[1]],x]],
Evaluate[viewDomain[viewPt[[2]],y]],Contours->{0.},ContourStyle->Thick,ClippingStyle->Automatic,ContourShading->None],VectorFieldPlot[field2[x,y],Evaluate[viewDomain[viewPt[[1]],x]],
Evaluate[viewDomain[viewPt[[2]],y]]],Evaluate[FilterRules[plotOpts,plotOptsType]],FrameLabel->Column[{"Blue: - Div,    Yellow: + Div","Increasing Div: Darker -> Lighter","Contour lines are constant Div"}]]],
Style["Graph of (Overscript[F, ->])[x,y] and (Overscript[∇, ->])·(Overscript[F, ->])."],
{{vFunction1,-(x^3)-(y^2),"(Subscript[F, 1])[x,y] = "}},
{{vFunction2,(x^3) (y^2),"(Subscript[F, 2])[x,y] = "}},
Style["Zoom"],
{{zoomFactor,1.7,""},6,0.1,ControlType->VerticalSlider,ControlPlacement->Left},
{{viewPt,{0,0},""},{-20,-20},{20,20},ControlPlacement->Right},
Delimiter,
{{paramA,1,"(+ integers) A"},0,50,1,Appearance->"Labeled",ControlPlacement->Bottom},
{{paramB,1,"(+/- integers) B"},-10,10,1,Appearance->"Labeled",ControlPlacement->Bottom},
{{paramC,0,"(+/- reals) C"},-1,1,Appearance->"Labeled",ControlPlacement->Bottom},Initialization:>(Needs["VectorFieldPlots`"])
]

Curl

Manipulate[

Module[{zoomScale,viewDomain,howBig, plotOpts,plotOptsType, paramSubst,field3},

(* ImageSize of graph in pixels *)
howBig=220; 

(* Compute domain/range based on location of center and zoom settings *)
zoomScale[factor_]=(factor^3);
viewDomain[centerpt_,var_:0,radius_:zoomScale[zoomFactor]]:=If[NumberQ[var],{-Abs[radius]+centerpt,Abs[radius]+centerpt},
{var,
-Abs[radius]+centerpt,Abs[radius]+centerpt}];

(* Substitution rules for parameters used in user-entered equations *)
paramSubst={A->paramA,B->paramB,C->paramC};

field3[x_,y_,z_]:={vFunction1,vFunction2,vFunction3}/.paramSubst;

(* Plot options common to all plots *)
plotOpts ={ImageSize->howBig};
plotOptsType=Options[VectorFieldPlot3D];

Show[VectorFieldPlot3D[field3[x,y,z],Evaluate[viewDomain[0,x]],
Evaluate[viewDomain[0,y]],Evaluate[viewDomain[0,z]],VectorHeads->True,PlotPoints->vectorDensity,ColorFunction->(RGBColor[1,0,0]&)],VectorFieldPlot3D[Evaluate[Curl[field3[x,y,z],Cartesian[x,y,z]]],Evaluate[viewDomain[0,x]],
Evaluate[viewDomain[0,y]],Evaluate[viewDomain[0,z]],VectorHeads->True,PlotPoints->vectorDensity,ColorFunction->(RGBColor[0,0,1]&)],Evaluate[FilterRules[plotOpts,plotOptsType]]]],
Style["Graph of (Overscript[F, ->]) and (Overscript[∇, ->])\[Cross](Overscript[F, ->]).       Red: (Overscript[F, ->]),   Blue: (Overscript[∇, ->])\[Cross](Overscript[F, ->])"],
{{vFunction1,(x^2)y,"(Subscript[F, 1])[x,y,z] = "}},
{{vFunction2,2x-3y,"(Subscript[F, 2])[x,y,z] = "}},
{{vFunction3,y (z^2),"(Subscript[F, 3])[x,y,z] = "}},
{{vectorDensity,7,"Vector density:"},1,20,1,Appearance->"Labeled"},
Style["Zoom"],
{{zoomFactor,1.2,""},6,0.1,ControlType->VerticalSlider,ControlPlacement->Left},
Delimiter,
{{paramA,1,"(+ integers) A"},0,50,1,Appearance->"Labeled",ControlPlacement->Bottom},
{{paramB,1,"(+/- integers) B"},-10,10,1,Appearance->"Labeled",ControlPlacement->Bottom},
{{paramC,0,"(+/- reals) C"},-1,1,Appearance->"Labeled",ControlPlacement->Bottom},Initialization:>(Needs["VectorFieldPlots`"];Needs["VectorAnalysis`"])
]